package composite.practice_01;

import java.util.ArrayList;
import java.util.List;

/**
 * 组合模式：实现形式就是实体类内部包含一个自己的集合
 *
 * @author yi qiang
 * @date 2021/6/1 10:13
 */
public class Employee {

    private String name;
    private String dept;
    private int salary;
    private List<Employee> subordinates;


    public Employee(String name,String dept, int sal) {
        this.name = name;
        this.dept = dept;
        this.salary = sal;
        subordinates = new ArrayList<>();
    }

    public void add(Employee e) {
        subordinates.add(e);
    }

    public void remove(Employee e) {
        subordinates.remove(e);
    }

    public List<Employee> getSubordinates(){
        return subordinates;
    }


    @Override
    public String toString(){
        return ("Employee :[ Name : "+ name
                +", dept : "+ dept + ", salary :"
                + salary+" ]");
    }
}
